package com.angel.application.commandgateways;

import com.angel.application.commandgateways.commands.PublishAngelHelpCommand;
import com.angel.domain.angelhelp.aggregates.AngelHelp;
import com.angel.domain.angelhelp.entities.AngelHelpInfo;
import com.angel.domain.angelhelp.repositories.AngelHelpRepository;
import com.angel.domain.angelhelp.valueobjects.AngelHelpInfoTitle;
import com.angel.domain.angeluser.valueobjects.AngelUserId;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/*
 * 更新关注微信公众号： 为了offer
 * @author parkin
 * @description
 * @date 2021/11/13
 */
@Service
@Slf4j
public class AngelHelpCommandService {

    private final AngelHelpRepository angelHelpRepository;

    public AngelHelpCommandService(AngelHelpRepository angelHelpRepository) {
        this.angelHelpRepository = angelHelpRepository;
    }

    /*
     * 更新关注微信公众号： 为了offer
     * @author parkin
     * @description 发布任务
     * @date 2021/11/13
     */
    public void publishAngelHelp(PublishAngelHelpCommand publishAngelHelpCommand) {

        AngelHelp angelHelp = new AngelHelp(
                AngelUserId.toAngelUserId(publishAngelHelpCommand.getAngelUserId()),
                new AngelHelpInfo(
                        new AngelHelpInfoTitle(publishAngelHelpCommand.getAngelMissionTitle()),
                        publishAngelHelpCommand.getTextContent(),
                        publishAngelHelpCommand.getImages()
                )
        );

        angelHelpRepository.save(angelHelp);
    }
}
